function trim(str) {
  const reg = /(^\s* | \s*$)/
  return str.replace(reg, '')
}


console.log(trim('    hoo'));
